home *** CD-ROM | disk | FTP | other *** search
/ The PC-SIG Library 10 / The PC-Sig Library - Shareware for the IBM PC and Compatibles (PC-SIG)(Tenth Edition Disks 1-2804)(1991).iso / PC_SIGCD / 04 / 1 / DISK0416.ZIP / ROFF43.C < prev    next >
C/C++ Source or Header  |  1985-08-10  |  7KB  |  232 lines

  1. /********************************************************/
  2. /*                                                      */
  3. /*                  ROFF4, Version 1.60                 */
  4. /*                                                      */
  5. /*(C) 1983,4 by Ernest E. Bergmann                      */
  6. /*              Physics, Building #16                   */
  7. /*              Lehigh Univerisity                      */
  8. /*              Bethlehem, Pa. 18015                    */
  9. /*                                                      */
  10. /* Permission is hereby granted for all commercial and  */
  11. /* non-commercial reproduction and distribution of this */
  12. /* material provided this notice is included.           */
  13. /*                                                      */
  14. /********************************************************/
  15. /*MAR 10, 1984*/
  16. #include "roff4.h"
  17. /****************************************/
  18. regist(s)       /*checks RLIST; creates new entry if needed;
  19.                 returns pointer to integer variable*/
  20. char *s;
  21. {
  22.       int *pw;
  23.       char *pc,*s2,*find2();
  24.       pw=(int *) find2(s,RLINK);
  25.       if(pw) return(pw); /*else create new entry*/
  26.       pw=(int *)TREND;
  27.       *pw=(int) RLINK;
  28.       pc=(char *) (pw+1);
  29.       s2=s;
  30.       transfer(&s2,&pc,'\0');
  31.       RLINK=(int *)TREND;
  32.       pw=(int *) pc;
  33.       *pw=REGDEF;
  34.       TREND=(char *) (pw+1);
  35.       return(pw);
  36. }
  37. /****************************************/
  38. dovar() /*process .RG request*/
  39. {
  40.       char typ, wbuf[MAXLINE];
  41.       int val, *pw;
  42.       getwrd(LINE,wbuf);
  43.       skip_blanks(LINE);
  44.       val=get_val(LINE,&typ);
  45.       getwrd(LINE,wbuf);
  46.       if(wbuf[0]==NUMSIGN && wbuf[1]=='\0')
  47.       {
  48.             set(&NEWPAG,val,typ,NEWPAG,1,9999);
  49.       }
  50.       else    {
  51.             pw=(int *) regist(wbuf);
  52.             set(pw,val,typ,REGDEF,0,9999);
  53.       }
  54. }
  55. /****************************************/
  56. dodiv()         /*process .DIversion*/
  57. {
  58.       char wbuf[MAXLINE],*pc,*pc1,*wb,*find2();
  59.       struct divfd *pd;
  60.       int *pw;
  61.       getwrd(LINE,wbuf);
  62.       if(getwrd(LINE,wbuf)!=WE_HAVE_A_WORD)
  63.       {
  64.             strcpy(wbuf,"JUNK.$$$");
  65.             fprintf(STDERR,"DIVERSION has no name, %s assumed\n",
  66.             wbuf);
  67.       }
  68.       ucstr(wbuf);
  69.       if(pd=(struct divfd *)find2(wbuf,DLINK))        /*if in table*/
  70.       {
  71.             if(!(pd->bf))          /*if not open*/
  72.                   if((pd->bf=fopen(wbuf,"w"))!=NULL)
  73.                         fprintf(STDERR,"<%s> rewritten for .DI\n",wbuf);
  74.             else {
  75.                   fprintf(STDERR,"<%s> cannot be rewritten\n",wbuf);
  76.                   exit();
  77.             }
  78.       }
  79.       else    /*not in table*/
  80.       {
  81.             pw=(int *)TREND;
  82.             *pw=DLINK;
  83.             pc1=pc=(char *)(pw+1);
  84.             wb=wbuf;
  85.             transfer(&wb,&pc,'\0');
  86.             DLINK=TREND;
  87.             pd=(struct divfd *) pc;
  88.             TREND =(char *) (pd+1);
  89.             pd->nm = pc1;
  90.             pd->ls = pd->cs = 0;
  91.             if((pd->bf=fopen(wbuf,"w"))==NULL)
  92.             {
  93.                   fprintf(STDERR,
  94.                   "Can't create <%s>\n",
  95.                   wbuf);
  96.                   exit();
  97.             }
  98.       }
  99.       while(fgets2(LINE,IOBUF))
  100.       {
  101.             if((*LINE==COMMAND)&&(comtyp(LINE)==ED)) break;
  102.             if(pc=(char *) macq(LINE))
  103.             {
  104.                   pbmac(pc,LINE);
  105.                   continue;
  106.             }
  107.             /*else*/
  108.             fputs(LINE,pd->bf);
  109.             (pd->ls)++;
  110.             (pd->cs) += 1+strlen(LINE);/*crlf=2*/
  111.       }
  112. }
  113. /****************************************/
  114. source()
  115. {
  116.       struct divfd *pd;
  117.       char name[MAXLINE],*find2();
  118.       getwrd(LINE,name);
  119.       if(getwrd(LINE,name)!=WE_HAVE_A_WORD)
  120.       {
  121.             fprintf(STDERR,".SO has no name\n");
  122.             return;
  123.       }
  124.       ucstr(name);
  125.       if(pd=(struct divfd *) find2(name,DLINK)) dclose(pd);
  126.       if(FPTR<FMAX) FSTACK[FPTR++]=IOBUF;
  127.       else    {
  128.             fprintf(STDERR,"FSTACK overflow\n");
  129.             exit();
  130.       }
  131.       if((IOBUF=fopen(name,"r"))!=NULL) return;
  132.       /*else*/
  133.       fprintf(STDERR,"Can't open <%s>\n",name);
  134.       endso();
  135. }
  136. /****************************************/
  137. showr() /*lists register names and contents*/
  138. {
  139.       int *pw, *pr;
  140.       char *pc;
  141.       fprintf(STDERR,"REGISTERS and <values>:\n");
  142.       pw=RLINK;
  143.       while(pw)
  144.       {
  145.             pc=(char *)(pw+1);
  146.             fprintf(STDERR,"%s ",pc);
  147.             pr=(int *) (pc+1+strlen(pc));
  148.             fprintf(STDERR,"<%d>\n",*pr);
  149.             pw=(int *) *pw;
  150.       }
  151.       dashes();
  152. }
  153. /****************************************/
  154. showd() /*shows all diversions and status*/
  155. {
  156.       int *pw;
  157.       char *pc;
  158.       struct divfd *pd;
  159.  
  160.       fprintf(STDERR, "Diversion files:\n");
  161.       pw=(int *)DLINK;
  162.       while(pw)
  163.       {
  164.             pc=(char *)(pw+1);
  165.             fprintf(STDERR,"%s: ",pc);
  166.             pd=(struct divfd *)(pc+1+strlen(pc));
  167.             fprintf(STDERR,"%d characters, %d lines [",
  168.             pd->cs, pd->ls );
  169.             if(pd->bf) fprintf(STDERR,"open]\n");
  170.             else    fprintf(STDERR,"closed]\n");
  171.             pw =(int *) *pw;
  172.       }
  173.       dashes();
  174. }
  175. /****************************************/
  176. dsclose()       /*flushes and closes all open diversions*/
  177. {
  178.       int *pw;
  179.       char *pc;
  180.       struct divfd *pd;
  181.  
  182.       pw = (int *) DLINK;
  183.       while(pw)
  184.       {
  185.             pc=(char *) (pw+1);
  186.             pd=(struct divfd *) (pc+1+strlen(pc));
  187.             if(pd->bf) dclose(pd);
  188.             pw=(int *) *pw;
  189.       }
  190. }
  191. /****************************************/
  192. dclose(pd)      /*flushes and closes diversion*/
  193. struct divfd *pd;
  194. {
  195.       if(pd&&(!(pd->bf))) return(FALSE);
  196.       fprintf(STDERR,"closing %s ",pd->nm);
  197.       putc(0x1a,pd->bf);
  198.       fflush(pd->bf);
  199.       if(fclose(pd->bf)==ERROR)
  200.             fprintf(STDERR,"****bad close****\n");
  201.       else    {
  202.             fprintf(STDERR,"[O.K.]\n");
  203.             pd->bf = FALSE;
  204.       }
  205.       return(TRUE);
  206. }
  207. /****************************************/
  208. ucstr(s)        /*convert s to upper case*/
  209. char *s;
  210. {
  211.       while(*s)
  212.       {
  213.             *s = toupper(*s);
  214.             s++;
  215.       }
  216. }
  217. /****************************************/
  218. endso() /*called upon EOF to return to previous input file*/
  219. {
  220.       if(FPTR)
  221.       {
  222.             fclose(IOBUF);
  223.             IOBUF=FSTACK[--FPTR];
  224.       }
  225.       BINP=0;
  226. }
  227. /****************************************/
  228. dashes()
  229. {
  230.       fprintf(STDERR,"-----------\n");
  231. }
  232.